package com.pureut.storage.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.StockOutInfoDetail;
import com.pureut.storage.dto.NewStockInfoDetailDto;
import com.pureut.storage.mapper.StockOutInfoDetailMapper;
import com.pureut.storage.service.StockInfoDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: CM
 * @date: 2023/2/2  15:11
 */
@Service
public class StockInfoDetailServiceImpl extends ServiceImpl<StockOutInfoDetailMapper, StockOutInfoDetail> implements StockInfoDetailService {

    @Resource
    StockOutInfoDetailMapper stockOutInfoDetailMapper;

    /**
     * 生产领料明细列表
     * @param docNum
     * @return
     */
    @Override
    public List<NewStockInfoDetailDto> getList(String docNum) {
        //获取单据状态字典数据
        List<SysDictData> statusArray = DictUtils.getDictCache("picking_outsource_detail_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        List<NewStockInfoDetailDto> list = stockOutInfoDetailMapper.getStockInfoDetailList(docNum);

        for (NewStockInfoDetailDto newStockInfoDetailDto : list) {
            newStockInfoDetailDto.setStatus(newStockInfoDetailDto.getStatus());
            newStockInfoDetailDto.setStatusDict(statusMap.get(newStockInfoDetailDto.getStatus()));
        }
        return list;
    }
}
